**Curtis RESTAT
**This do file generates the results found in Panels A and B of Table 2
**Change to directory where data and code were downloaded


*cd /*   */

set matsize 1500
clear all
set more off

use cbp_st_table2,clear

do dataclean_table2.do

gen empweight2=emp if year==1998
bysort stateind:carryforward empweight2,replace

so stateind year

gen NBPstr="NBP" if NBP==1
replace NBPstr="west" if NBPstr==""
gen NBPind=NBPstr+naics

drop yeardum*
tab year,gen(yeardum)

gen trend=year-1997
qui tab fipstate,gen(STdum)
foreach var of varlist ind1-ind21 {
qui gen trend`var'=`var'*trend
}

foreach x of varlist STdum1-STdum49 {
qui gen trend`x'=`x'*trend
}

/* Generate Seperate NBP/West Trends by Industry*/
forvalues i = 1(1)21 {
  qui gen eindtrend`i' = trendind`i'*NBP
 }
forvalues i = 1(1)21 {
  qui gen windtrend`i' = trendind`i'*((NBP-1)^2)
 }
tostring NBP,replace
gen yearindreg=yearind+"_"+NBP


qui tab yearind,gen(yearinddum)
qui tab STyear, gen(STyeardum)
qui tab stateind, gen(stateinddum)

/* Defines RHS variables to be included in every regression*/
mac def rhs_vars "postxint intxNBP postxNBP  "




/*Full FE model with E/W Ind Trends but with weights*/
*Column 1
qui eststo:areg lemp postxNBPxint postxint intxNBP postxNBP yeardum* [aweight=empweight2],abs(stateind) rob cluster(NBPind)
*Column 2
qui eststo:areg lemp postxNBPxint postxint intxNBP postxNBP yearinddum* trendSTdum* [aweight=empweight2],abs(stateind) rob cluster(NBPind)
*Column 3
qui eststo:areg lemp postxNBPxint postxint intxNBP yearinddum* STyeardum* [aweight=empweight2],abs(stateind) rob cluster(NBPind)
*Column 4
qui eststo:areg lemp postxNBPxint postxint intxNBP postxNBP yeardum* windtrend* eindtrend*[aweight=empweight2],abs(stateind) rob cluster(NBPind)
*Column 5
qui eststo:areg lemp postxNBPxint postxint intxNBP postxNBP yearinddum* trendSTdum* windtrend* eindtrend*[aweight=empweight2],abs(stateind) rob cluster(NBPind)
*Column 6
qui eststo:areg lemp postxNBPxint postxint intxNBP  yearinddum* STyeardum* windtrend* eindtrend*[aweight=empweight2],abs(stateind) rob cluster(NBPind)

outreg2 [est1 est2 est3 est4 est5 est6] using "table2a.tex",keep(postxNBPxint postxNBP) nocons replace

eststo clear
/*With Energy Controls*/
*Column 1
qui eststo:areg lemp postxNBPxint postxint intxNBP postxNBP  natgasxe* coalxe* oilxe* /*per**/ yeardum* [aweight=empweight2],abs(stateind) rob cluster(NBPind)
*Column 2
qui eststo:areg lemp postxNBPxint postxint intxNBP postxNBP natgasxe* coalxe* oilxe* /*per**/ yearinddum* trendSTdum* [aweight=empweight2],abs(stateind) rob cluster(NBPind)
*Column 3
qui eststo:areg lemp postxNBPxint postxint intxNBP natgasxe* coalxe* oilxe* /*per**/ yearinddum* STyeardum* [aweight=empweight2],abs(stateind) rob cluster(NBPind)
*Column 4
qui eststo:areg lemp postxNBPxint postxint intxNBP postxNBP natgasxe* coalxe* oilxe* /*per**/ yeardum* windtrend* eindtrend*[aweight=empweight2],abs(stateind) rob cluster(NBPind)
*Column 5
qui eststo:areg lemp postxNBPxint postxint intxNBP postxNBP natgasxe* coalxe* oilxe* /*per**/ yearinddum* trendSTdum* windtrend* eindtrend*[aweight=empweight2],abs(stateind) rob cluster(NBPind)
*Column 6
qui eststo:areg lemp postxNBPxint postxint intxNBP natgasxe* coalxe* oilxe* /*per**/ yearinddum* STyeardum* windtrend* eindtrend*[aweight=empweight2],abs(stateind) rob cluster(NBPind)

outreg2 [est1 est2 est3 est4 est5 est6] using "table2b.tex",keep(postxNBPxint postxNBP) nocons replace
